﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using DAL;
using BUS;

namespace WEBSITE_BANDEAL.Admin
{
    public partial class SanPham_List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lit_title.Text = "Quản lý sản phẩm";
            lit_title_header.Text = "Danh sách sản phẩm";
            if(!IsPostBack)
            {
                LoadData();
            }
        }
        public void LoadData()
        {            
            SANPHAMcollection sp = SAN_PHAMBUS.GetAll();
            Repeater1.DataSource = sp;
            Repeater1.DataBind();        
           
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //Literal lit_Ma = (Literal)e.Item.FindControl("lit_Ma");
                Literal lit_trangthai = (Literal)e.Item.FindControl("lit_trangthai");
                Literal lit_tencha = (Literal)e.Item.FindControl("lit_tencha");
                Literal lit_TGBD = (Literal)e.Item.FindControl("lit_TGBD");
                Literal lit_TGKT = (Literal)e.Item.FindControl("lit_TGKT");
                Image img = (Image)e.Item.FindControl("img");
                SAN_PHAM sp = (SAN_PHAM)e.Item.DataItem;
                lit_tencha.Text = LOAI_SAN_PHAMBUS.GetCha(sp.Maloaisp);
                lit_TGBD.Text = sp.Tgbatdau.ToString("dd/MM/yyyy");
                lit_TGKT.Text = sp.Tgketthuc.ToString("dd/MM/yyyy");
                img.ImageUrl = sp.Hinhdaidien;
                if (sp.Trangthai == 1)
                {
                    lit_trangthai.Text = " <img src='../Template/images/admin/check.png' alt='" + sp.Masp.ToString() + "' onClick='AnHien(" + sp.Masp + ")' title='Hiện' style='margin:10px;cursor:pointer;'  />";
                }
                else
                {
                    lit_trangthai.Text = "<img src='../Template/images/admin/cancel.png' alt='" + sp.Masp.ToString() + "' onClick='AnHien(" + sp.Masp + ")' title='Ẩn' style='margin:10px;cursor:pointer;' />";
                }
            }
        }
    }
}